package com.huluobo.user.view

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Divider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import coil.compose.AsyncImage
import com.google.gson.Gson
import com.huluobo.lib_base.BaseTitle
import com.huluobo.user.R
import com.huluobo.user.entity.ApproveEntityItem

/**
 *  Created by LC on 2025/4/6.
 */
@Composable
fun ApprovePage(navHostController: NavHostController, json: String) {
    val entity = Gson().fromJson(json, ApproveEntityItem::class.java)

    Column(Modifier.padding(20.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
        BaseTitle(title = "请假详情", navHostController = navHostController)
        Spacer(modifier = Modifier.height(10.dp))
        Text(text = "申报人信息", color = Color.Blue)
        Card(
            border = BorderStroke(1.dp, Color.LightGray),
            colors = CardDefaults.cardColors(containerColor = Color.White),
            modifier = Modifier.fillMaxWidth()
        ) {
            Row(
                Modifier
                    .fillMaxWidth()
                    .padding(20.dp)
            ) {
                AsyncImage(
                    model = "https://img0.baidu.com/it/u=788800651,2030194952&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1730307600&t=9c17b588a934b0ccf76349e5e5b7ca08",
                    contentDescription = "",
                    modifier = Modifier
                        .size(80.dp)
                        .clip(CircleShape),
                    contentScale = ContentScale.Crop
                )
                Spacer(modifier = Modifier.width(20.dp))
                Column(Modifier.height(80.dp), verticalArrangement = Arrangement.SpaceAround) {
                    Text(text = entity.staffName)
                    Text(text = entity.deptName)
                }
            }
        }

        Spacer(modifier = Modifier.height(10.dp))
        Text(text = "请假详情", color = Color.Blue)
        Spacer(modifier = Modifier.height(10.dp))
        Text(text = "请假方式 : ${entity.type}")
        Text(text = "开始时间 : ${entity.startTime}")
        Text(text = "结束时间 : ${entity.endTime}")
        Text(text = "请假时长 : ${entity.hours}")
        Text(text = "请假原因 : ${entity.reason}")
        Spacer(modifier = Modifier.height(10.dp))
        Row(Modifier.padding(start = 30.dp)) {
            Column(horizontalAlignment = Alignment.CenterHorizontally) {
                AsyncImage(
                    model = "https://img0.baidu.com/it/u=788800651,2030194952&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1730307600&t=9c17b588a934b0ccf76349e5e5b7ca08",
                    contentDescription = "",
                    modifier = Modifier
                        .size(40.dp)
                        .clip(CircleShape),
                    contentScale = ContentScale.Crop
                )
                Divider(
                    Modifier
                        .width(1.dp)
                        .height(30.dp)
                )
                val img = if (entity.status == "通过") R.drawable.ic_action_ok else R.drawable.ic_action_refuse
                Image(painter = painterResource(id = img), contentDescription = "", modifier = Modifier.size(40.dp))
            }
            Spacer(modifier = Modifier.width(10.dp))
            Column {
                Text(text = "已提交")
                Text(text = "申报时间 : ${entity.createTime}", color = Color.Gray, fontSize = 12.sp)
                Spacer(modifier = Modifier.height(30.dp))
                Text(text = entity.status)
                Text(text = "审批时间时间 : ${entity.comTime}", color = Color.Gray, fontSize = 12.sp)
            }
        }
    }
}